/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.fatecpg.songs.entity;

import br.com.fatecpg.songs.entity.util.Activable;
import br.com.fatecpg.songs.entity.util.UserStatus;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 *
 * @author Marcos
 */
@SequenceGenerator(name="SEQUSER", sequenceName="SEQUSER", allocationSize=1, initialValue=1)
@Entity(name="User")
@Table(name="TB_USER")
public class User implements Activable{
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="SEQUSER")
    @Column(name="id")
    private Long id;
    
    @Column(name = "name")
    private String name;
    
    @Column(name = "login_name")
    private String loginName;
    
    @Column(name = "password")
    private String password;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "active")
    private UserStatus userStatus;

    @Override
    public Long getId() {
        return id;
    }      

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }        

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }           

    public UserStatus getUserStatus() {
        return userStatus;
    }
        
    public void setUserStatus(UserStatus userStatus) {
        this.userStatus = userStatus;
    }            
    
    @Override
    public void active(){
        setUserStatus(UserStatus.Y);
    }
    
    @Override
    public void deactive(){
        setUserStatus(UserStatus.N);
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 37 * hash + (this.id != null ? this.id.hashCode() : 0);
        hash = 37 * hash + (this.loginName != null ? this.loginName.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final User other = (User) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        if ((this.loginName == null) ? (other.loginName != null) : !this.loginName.equals(other.loginName)) {
            return false;
        }
        return true;
    }          
}
